/**
 * losenote.com Inc.
 * Copyright (c) 2013-2013 All Rights Reserved.
 */
package com.losenote.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.losenote.base.template.AbstractServiceImpl;
import com.losenote.base.template.BlankCallback;
import com.losenote.core.CategoryComponent;
import com.losenote.model.CategoryItem;
import com.losenote.service.CategoryService;
import com.losenote.service.result.CategoryResult;

/**
 * 目录查询服务
 * 
 * @author danjingyu
 * @version $Id: CategoryQueryServiceImpl.java, v 0.1 2013-9-12 下午6:59:30 danjingyu Exp $
 */
public class CategoryServiceImpl extends AbstractServiceImpl implements CategoryService {

    /**分类操作服务*/
    @Autowired
    private CategoryComponent categoryComponent;

    /**
     * 查询根节点 
     * 
     * @see com.losenote.service.CategoryService#queryChidren()
     */
    @Override
    public CategoryResult queryChidren(final int fatherId) {
        CategoryResult result = serviceTemplate.executeWithoutTransaction(CategoryResult.class,
            new BlankCallback() {
                public CategoryResult executeService() {
                    List<CategoryItem> categoryItems = categoryComponent
                        .queryCategoryChidren(fatherId);
                    CategoryResult result = new CategoryResult();
                    result.setCategoryItems(categoryItems);
                    return result;
                }

            });
        return result;
    }

    @Override
    public CategoryResult queryById(final int categoryId) {
        CategoryResult result = serviceTemplate.executeWithoutTransaction(CategoryResult.class,
            new BlankCallback() {
                public CategoryResult executeService() {
                    CategoryItem categoryItem = categoryComponent.queryCategoryId(categoryId);
                    CategoryResult result = new CategoryResult();
                    result.setCategoryItem(categoryItem);
                    return result;
                }

            });
        return result;
    }

    public void setCategoryComponent(CategoryComponent categoryComponent) {
        this.categoryComponent = categoryComponent;
    }

}
